# coding=utf-8
import wx

class TechFindFrame(wx.Frame):
    
    def __init__(self,mainframe):
        wx.Frame.__init__(self,None,-1,u"查找",style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX),size=(300,200))
        self.mainframe=mainframe
        self.Center()
        self.panel=wx.Panel(self)
        self.titletext=wx.StaticText(self.panel,-1,label=u"查找",pos=(50,50))
        fieldlist=[u"标题",u"内容"]
        self.fieldcombo=wx.ComboBox(self.panel, -1, u"标题", (80, 50), wx.DefaultSize,fieldlist, wx.CB_DROPDOWN)
        self.contenttext = wx.TextCtrl(self.panel, -1,pos=(140,50))
        self.okbutton=wx.Button(self.panel,label=u"确定",pos=(80,120))
        self.closebutton=wx.Button(self.panel,label=u"关闭",pos=(160,120))
        self.Bind(wx.EVT_BUTTON,self.OnOk,self.okbutton)
        self.Bind(wx.EVT_BUTTON,self.OnExit,self.closebutton)
        self.Bind(wx.EVT_CLOSE,self.OnDestroy)
    
    def OnOk(self,event):
        item=self.fieldcombo.GetValue().encode('gbk','ignore')
        field="title"
        if item==u"内容":
            field="content"       
        self.mainframe.where="and "+field+" like '%"+self.contenttext.GetValue()+"%'"
        self.mainframe.LoadData()
        self.Close()
    
    def OnExit(self,event):
        self.Close()
    
    def OnDestroy(self,event):
        self.Destroy()